API Management (1 / 25): In a company's API system hosted behind an Azure API Management service, you are tasked with implementing response caching. The user ID of the client must first be detected and saved. Then, the response must be cached specifically for that saved user ID. What types of policies should be used to accomplish this task?
Answer:
Both inbound and outbound policies
- Inbound Policy: The inbound policy is used to extract and save the user ID from the incoming request. The
<set-variable>
policy is used to save the user ID, and the <cache-lookup>
policy with a custom key is used to check if a cached response exists for that user ID.
- Outbound Policy: The outbound policy is used to store the response in the cache. The
<cache-store>
policy with a custom key is used to cache the response specifically for the saved user ID.
Therefore, both inbound and outbound policies are needed to meet the requirements.